package com.thoughtservice.jspdoc.processors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thoughtservice.jspdoc.JSPFileList;
import com.thoughtservice.jspdoc.JSPPage;
import com.thoughtservice.jspdoc.RE;
import com.thoughtservice.jspdoc.RESyntaxException;
import com.thoughtservice.jspdoc.utils.ProcessorUtils;


public class ProcessForm implements DocProcessor{

	private final static Logger LOG = LoggerFactory.getLogger(ProcessForm.class);

	public boolean process(JSPPage p, String pc, JSPFileList fileList)
			throws RESyntaxException {
		LOG.trace("Entering {}", "ProcessForm");
		RE re;
		int index;
		re = new RE("<form[:space:]*action=\"[^\"<]*\"[:space:]*method=\"[^\"<]*\"");
		index = 0;
		while (re.match(pc, index)) {
			//			System.out.println(re.getParen(0));
			String link = re.getParen(0);
			index = re.getParenEnd(0); 
			// Don't process mailto links
			if (link.indexOf("\"mailto:") == -1) {
				link = ProcessorUtils.figureForm(link, p, JSPPage.LINKSTOFORM);
			}
		}
		LOG.trace("Exiting {}", "ProcessForm");
	
		return false;
	}
}
